import java.util.*;

/**
 * Created by qtbui on 2017/9/21.
 */

class TreeNode
{
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}

class Solution
{
	public boolean isSymmetric(TreeNode root)
	{
		String left=getTreeByLeft(root);
		String right=getTreeByRight(root);
		return left.equals(right);
	}

    private String getTreeByLeft(TreeNode tn)
    {
	    if (tn == null)
	    {
	    	return " ";
	    }

	    String val=String.valueOf(tn.val);
	    String left=getTreeByLeft(tn.left);
	    String right=getTreeByLeft(tn.right);
	    return val+left+right;
    }

    private String getTreeByRight(TreeNode tn)
    {
	    if (tn == null)
	    {
		    return " ";
	    }

	    String val=String.valueOf(tn.val);
	    String right=getTreeByRight(tn.right);
	    String left=getTreeByRight(tn.left);
	    return val+right+left;
    }
}

public class test
{
    public static void main(String[] args)
    {
		TreeNode tn=new TreeNode(0);
		tn.left=new TreeNode(1);
		tn.right=new TreeNode(1);
		tn.left.left=new TreeNode(2);
		tn.left.right=new TreeNode(3);
		tn.right.left=new TreeNode(3);
		tn.right.right=new TreeNode(2);

		System.out.println(new Solution().isSymmetric(tn));
    }
}
